import win32api, win32con, winerror
import client
import sys
from PyQt4 import QtGui 

def showParamDef():
    print "You must specify a host, timeout(miliseconds), port number."
    print "For example:"
    print " runclient.exe 192.168.0.1 5000 23"
    print "or "
    print " runclient.exe localhost 3000 50"
    print "* Created by Xevi Terradellas ( xeviterr@gmail.com )"

try:

    app = QtGui.QApplication(sys.argv, QtGui.QApplication.Tty)
    
    host = "localhost"
    timeout = 5000
    port = 23
    if len(sys.argv) > 0:
        try:
            host = sys.argv[1];
            timeout = int(sys.argv[2]);
            port = int(sys.argv[3]);
        except Exception, err:
             print "---- Your parameters are incorrect ----"
             raise Exception
    else:
        raise Exception
    
    print "Running with following parameters:"
    print "HOSTNAME:" + host
    print "TIMEOUT:" + str(timeout)
    print "PORT:" + str(port)
    clientProc = client.ClientProcess(host, timeout, port, None)
    sys.exit(app.exec_())    

except Exception, err:
    print err
    showParamDef()

finally:
    app.quit()
    sys.exit()
